package au.com.centrumsystems.hudson.plugin.buildpipeline;

import hudson.model.AbstractProject;
import hudson.model.DependencyGraph.Dependency;

import java.util.Map;

/**
 * @author <a href="mailto:nicolas.deloof@cloudbees.com">Nicolas De loof</a>
 */
public class JoinProjectForm extends ProjectForm {

    public JoinProjectForm(JoinProjectForm previousSibling) {
        super(previousSibling.getName());
        this.previousSibling = previousSibling;
        previousSibling.setNextSibling(this);
    }

    public JoinProjectForm(AbstractProject<?, ?> project, Map<Dependency, JoinProjectForm> joins) {
        super(project, joins);
    }

    public String getStyle() {
        return super.getStyle() + " join";
    }

    public boolean isJoin() {
        return true;
    }

    private JoinProjectForm nextSibling;

    private JoinProjectForm previousSibling;

    public boolean isFirstSibling() {
        return previousSibling == null;
    }

    public boolean isLastSibling() {
        return nextSibling == null;
    }

    @Override
    public boolean isVisible() {
        return isFirstSibling();
    }

    public JoinProjectForm getNextSibling() {
        return nextSibling;
    }

    public void setNextSibling(JoinProjectForm nextSibling) {
        this.nextSibling = nextSibling;
    }

    public JoinProjectForm getPreviousSibling() {
        return previousSibling;
    }

    public void setPreviousSibling(JoinProjectForm previousSibling) {
        this.previousSibling = previousSibling;
    }

}
